package com.photoeditor.demo.ui.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.photoeditor.R;

public class VirtualRateDialog extends BaseVirtualRateDialog implements View.OnClickListener {

    private TextView mCancelView;
    private TextView mSureView;
    private Context mContext;

    public static void showVirtualRateDialog(Context context) {
        VirtualRateDialog rateDialog = new VirtualRateDialog(context);
        rateDialog.setCanceledOnTouchOutside(true);
        rateDialog.show();
    }

    public VirtualRateDialog(Context context) {
        super(context);
        mContext = context;
    }

    @Override
    public void initDefaultView(final Context context) {
        super.initDefaultView(context);
        setContentView(R.layout.dialog_virtual_rate);

        mCancelView = findViewById(R.id.cancel);
        mCancelView.setOnClickListener(this);

        mSureView = findViewById(R.id.sure);
        mSureView.setOnClickListener(this);

        findViewById(R.id.ic_close).setOnClickListener(this);

        DialogStatistic.rateShow(RateGuide.getWhere());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cancel:
                VirtualRateBadDialog.showRateDialogVirtual(mContext);
                DialogStatistic.rateBadComm(RateGuide.getWhere());
                dismiss();
                break;
            case R.id.sure:
                VirtualRateGoodDialog.showRateDialogVirtual(mContext);
                DialogStatistic.rateGoodComm(RateGuide.getWhere());
                dismiss();
                break;
            case R.id.ic_close:
                dismiss();
                DialogStatistic.rateClose(RateGuide.getWhere());
                if (mListener != null && mListener.get() instanceof IRateDialogListener) {
                    ((IRateDialogListener) mListener.get()).onCloseClick();
                }
                break;
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        DialogStatistic.rateClose(RateGuide.getWhere());
    }
}
